

<?php
/*@var $this Controller */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title><?php echo h($this->pageTitle) ?></title>
    <link rel="stylesheet" type="text/css" href="<?php echo WWW_URL ?>css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo WWW_URL ?>css/style.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo WWW_URL ?>css/custom.css"/>
    <script type="text/javascript" src="<?php echo WWW_URL ?>js/parse-1.2.12.min.js"></script>
    <script type="text/javascript" src="<?php echo WWW_URL ?>js/underscore.js"></script>
    <script type="text/javascript" src="<?php echo WWW_URL ?>app/config.js"></script>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>

    <script>
        var placeId = "<?php echo $this->placeId ?>";
        var lang = '<?php echo app()->getLanguage() ?>';
        var placeQrCode = '<?php echo CommonHelper::generateQRCode(app()->createAbsoluteUrl('/place/index',array('id'=>$this->placeId)))?>';
        // content of popup
        var termContent = '';
        var faqContent = '';
        var aboutContent = '';
        var defaultUrl = '<?php echo app()->createUrl('/place/index')?>';
        // language
    </script>

</head>


<body>


<!--<div class="message-container">
    <div class="content">rwer</div>
</div>
-->
<div class="load" style="width: 80px; height: 80px; padding: 15px; position: absolute; z-index: 5000; display: none">
    <img src="<?php echo WWW_URL ?>/images/loading.gif"/>
</div>


<div class="container">
    <div class="top-bar">
        <div class="step">
            <div class="place-select-container">
                <img src="<?php echo FRONT_SITE_URL ?>www/images/current-place.png" alt="">
                <?php if (!empty($this->listPlace)) : ?>
                    <select id="place-select">
                        <option value="np">Create a new place</option>
                        <?php foreach ($this->listPlace->results as $item) : ?>

                            <option value="<?php echo $item->objectId ?>" <?php echo ($item->objectId == $this->placeId) ? ' selected' : '';?>>
                                <?php echo $item->name ?></option>

                            <?php endforeach; ?>
                    </select>
                <?php endif; ?>
            </div>
            <div class="account">
                <a href="<?php echo url('/site/logout') ?>" class="logout">LogOut</a>
                <ul class="list-ac">
                    <li><a href="#" class="active">
                            <img src="<?php echo WWW_URL ?>images/icon.jpg"/> Account <span class="cong">+</span></a>
                    </li>
                    <li><a href="#"><img src="<?php echo WWW_URL ?>images/icon1.jpg"/> Setting</a>
                        <ul>

                            <li><a href="#" id="delete-place"><?php echo t('Delete place') ?></a></li>
                            <li>---</li>
                            <li><a href="#" class="change-lang"><?php echo t('Change language') ?></a></li>
                            
                            <li>---</li>
                            <li><a href="#" id="about-link"><?php echo t('About') ?></a></li>
                            <li><a href="#" id="faq-link"><?php echo t('FAQ') ?></a></li>
                            <li><a href="#" id="term-link"><?php echo t('Terms and conditions') ?></a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <!--account-->

            <div class="logo">
                <a href="<?php echo FRONT_SITE_URL ?>">
                    <img src="<?php echo WWW_URL ?>images/logo.png"/>
                </a>
            </div>
            <div class="line"></div>

            <?php $this->widget('application.widgets.WQuickNav') ?>

        </div>
    </div>
    <!--top-bar-->

    <div class="title">
        <h2>NiceTips</h2>

        <?php $controllerName = app()->controller->id;
        switch ($controllerName) {
            case 'place' :
            {
                if ($this->placeId == '') {
                    echo t('<p>Welcome to NiceTips at a moment <br/> are no place that you manage, add new place!</p>');
                }
                break;
            }
            case 'team':
            {
                echo t('<p>Please list all the people that work <br/>in your organization/mandatory!</p>');
                break;
            }
            case 'tips' :
            {
                echo t('<p>Please complete the infomation <br/> necessary to manage the tips !</p>');
                break;
            }

            case 'vote' :
            {
                echo t('<p>Welcome <br/> lorem ..... !</p>');
                break;
            }

        }
        ?>

    </div>
    <!--title-->

    <div class="content">
        <?php if (user()->hasFlash('error')) : ?>

            <div class="alert alert-error"><?php echo user()->getFlash('error') ?></div>

        <?php endif; ?>

        <?php echo $content ?>


        <div class="tad-bot">
            <?php
            $this->widget('zii.widgets.CBreadcrumbs', array(
                'links' => array(
                    t('Place') => array('/place/index', 'id' => $this->placeId),
                    t('Team') => array('/team/index', 'id' => $this->placeId),
                    t('Tips') => array('/tips/index', 'id' => $this->placeId),
                    t('Vote') => array('/vote/index', 'id' => $this->placeId),
                ),
                'separator' => ' >',
                'homeLink' => false,
                'activeLinkTemplate' => '<a href="{url}" class="breadcummb-items">{label}</a>',

            ));
            ?>
        </div>

        <div class="footer">
            <div class="nut-sli">
                <?php
                $this->widget('zii.widgets.CBreadcrumbs', array(
                    'links' => array(
                        '' => array('/place/index', 'id' => $this->placeId),
                        ' ' => array('/team/index', 'id' => $this->placeId),
                        '  ' => array('/tips/index', 'id' => $this->placeId),
                        '   ' => array('/vote/index', 'id' => $this->placeId),
                    ),
                    'separator' => ' ',
                    'homeLink' => false,
                    'activeLinkTemplate' => '<a href="{url}" class="breadcummb-bullet-items">{label}</a>',
                ));
                ?>
            </div>
            <p><?php echo t('Copyright 2013 - All rights reserved') ?>d</p>
        </div>

    </div>
    <!--content-->

</div>
<!--container-->

<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'lang-dialog',
    // additional javascript options for the dialog plugin
    'options' => array(
        'title' => 'Select your language',
        'autoOpen' => false,
        'width' => '350',
        'height' => '100',
        'show' => array(
            'effect' => 'fade',
            'duration' => 700,
        ),
        'hide' => array(
            'effect' => 'fade',
            'duration' => 400,
        )
    ),
    'htmlOptions' => array(
        'style' => 'z-index:1000',
    )

));
?>
<?php echo CHtml::beginForm(app()->createUrl('/site/selectlang'), 'post', array('id' => 'lang-form')); ?>
<div>
    <?php echo CHtml::dropDownList('lang', '', array('en' => 'English', 'it' => 'Italia', 'de' => 'Deustch')) ?>
    <?php echo CHtml::submitButton('Select', array('class' => 'btn select-lang-btn')) ?>
</div>
<?php echo CHtml::endForm() ?>


<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');

?>

<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'about-dialog',
    // additional javascript options for the dialog plugin
    'options' => array(
        'title' => 'About',
        'autoOpen' => false,
        'modal' => true,
        'width' => '350',
        'height' => '100',
        'draggable' => false,
        'closeOnEscape' => true,
        'show' => array(
            'effect' => 'fade',
            'duration' => 700,
        ),
        'hide' => array(
            'effect' => 'fade',
            'duration' => 400,
        )

    ),
    'htmlOptions' => array(
        'style' => 'z-index:1000',
    )

));
?>

<div id="about-content">
    <p>Content of about here</p>
</div>

<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');

?>

<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'faq-dialog',
    // additional javascript options for the dialog plugin
    'options' => array(
        'title' => 'FAQ',
        'autoOpen' => false,
        'modal' => true,
        'width' => '350',
        'height' => '100',
        'show' => array(
            'effect' => 'fade',
            'duration' => 700,
        ),
        'hide' => array(
            'effect' => 'fade',
            'duration' => 400,
        )
    ),
    'htmlOptions' => array(
        'style' => 'z-index:1000',
    )

));
?>
<div id="faq-content">
    <p>Content of faq here</p>
</div>

<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');

?>

<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'term-dialog',
    // additional javascript options for the dialog plugin
    'options' => array(
        'title' => 'Term',
        'autoOpen' => false,
        'modal' => true,
        'width' => '350',
        'height' => '100',
        'show' => array(
            'effect' => 'fade',
            'duration' => 700,
        ),
        'hide' => array(
            'effect' => 'fade',
            'duration' => 400,
        )
    ),
    'htmlOptions' => array(
        'style' => 'z-index:1000',
    )

));
?>

<div id="term-content">
    <p>Content of term here</p>
</div>


<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');

?>

<!-- <script src="<?php /*echo WWW_URL */?>js/dropkick.js" type="text/javascript" charset="utf-8"></script>-->
<script>
    $(document).ready(function () {

        h = $(window).height();
        h_header = 0;
        h_pop = 480;
        h_top = (parseInt(h) - parseInt(h_pop)) / 2;
        $('.intro').attr('style', 'top:' + h_top + 'px;');
        $('.img-intro').attr('style', 'height:' + h + 'px;');
    });
</script>

<link rel="stylesheet" href="<?php echo FRONT_SITE_URL ?>www/css/dropkick.css">
<!--<script src="<?php /*echo FRONT_SITE_URL*/?>www/js/dropkick.js" type="text/javascript" charset="utf-8"></script>-->
<script type="text/javascript">
    $(function () {
        //  $('.baby_bear').dropkick();
        //     $('.mama_bear').dropkick();
        //  $('.papa_bear').dropkick();
    });
</script>

</body>
</html>
<script>

    var controller = '<?php echo app()->controller->id?>';
    deletePlaceUrl = '<?php echo app()->createUrl('/place/delete')?>';   // URL FOR delete place
    indexPlaceUrl = '<?php echo app()->createUrl('/place/index')?>';

    $(document).ready(function () {

        var faqQuery = new Parse.Query('FAQ');
        var termQuery = new Parse.Query('Term');
        var aboutQuery = new Parse.Query('About');
        faqQuery.equalTo('countryCode', lang);
        faqQuery.find({
            success: function (faqs) {
                faqContent = faqs[0].get('text');
                $('#faq-content p').text(faqContent);
            }
        })
    });

    $(document).on('change', '#place-select', function () {
        var placeId = $('#place-select option:selected').val();

        var redirectUrl;

        switch (controller) {

            case 'place':
            {
                redirectUrl = '<?php echo app()->createUrl('/place/index')?>';
                redirectUrl = redirectUrl + '?id=' + placeId;
                break;
            }
            case 'team' :
            {
                redirectUrl = '<?php echo app()->createUrl('/team/index')?>';
                redirectUrl = redirectUrl + '?id=' + placeId;
                break;
            }

            case 'tips':
            {
                redirectUrl = '<?php echo app()->createUrl('/tips/index')?>';
                redirectUrl = redirectUrl + '?id=' + placeId;
                break;
            }

            case 'vote' :
            {
                redirectUrl = '<?php echo app()->createUrl('/vote/index')?>';
                redirectUrl = redirectUrl + '?id=' + placeId;

                break;
            }
        }

        window.location.href = redirectUrl;

    })

    $(document).ready(function () {
        var top = $(document).height() / 2;
        var left = $(document).width() / 2;
        $('.load').css('top', top);
        $('.load').css('left', left);


        for (var i = 0; i < $('.breadcummb-items').length; i++) {
            $('.breadcummb-items').eq(i).addClass('inactive');
            $('.breadcummb-bullet-items').eq(i).addClass('inactive');

        }
        switch (controller) {

            case 'place':
            {
                $('.breadcummb-items').eq(0).addClass('active');
                $('.breadcummb-bullet-items').eq(0).addClass('active');
                $('#business-search').focus();
                break;
            }
            case 'team' :
            {
                $('.breadcummb-items').eq(1).addClass('active');
                $('.breadcummb-bullet-items').eq(1).addClass('active');
                break;
            }

            case 'tips':
            {
                $('.breadcummb-items').eq(2).addClass('active');
                $('.breadcummb-bullet-items').eq(2).addClass('active');
                break;

            }
            case 'vote' :
            {
                $('.breadcummb-items').eq(3).addClass('active');
                $('.breadcummb-bullet-items').eq(3).addClass('active');
                break;
            }
        }
    })

    /*
     @menu : change the place name
     */

    $(document).on('click', '.change-lang', function () {

        $('#lang-dialog').dialog("open");
    });

    $(document).on('click', '.select-lang-btn', function () {
        $('#lang-form').submit();
    })

    $(document).on('click', '#faq-link', function () {

        $('#faq-dialog').dialog("open");
    })


    $(document).on('click', '#term-link', function () {

        $('#term-dialog').dialog("open");
    })

    $(document).on('click', '#about-link', function () {

        $('#about-dialog').dialog("open");
    })

    $(document).on('click', '#delete-place', function () {

        if (placeId != '') {
            var cf = confirm('Do you want to delete current place');
            if (cf) {
                var place = new Place();
                var placeView = new PlaceView({model: place});
                placeView.deletePlace(placeId);
            }
        } else {
            alert('No place to delete. Please select one');
        }

    })
    /*
     @redicrect to the place controller when select create new place
     */

    $(document).on('change', '#place-select', function () {
        var select = $(this).find('option:selected').val();
        if (select == 'np') {
            window.location.href = '<?php echo app()->createUrl('/place/index',array('id'=>'np'))?>';
        }

    });

</script>
